//
//  THMajorDetailServiceInfoViewController.m
//  TreeHole
//
//  Created by apple on 2020/9/22.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THMajorDetailServiceInfoViewController.h"
#import <WebKit/WebKit.h>
@interface THMajorDetailServiceInfoViewController ()<WKNavigationDelegate>
@property(nonatomic, strong) NSString             *urlStr;
@property(nonatomic, strong) NSString             *h5String;
@property(nonatomic, strong) WKWebView            *webView;
@end

@implementation THMajorDetailServiceInfoViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.contentInset = UIEdgeInsetsZero;
    UIScrollView * scrollView = [self.parentViewController valueForKey:@"scrollView"];
    self.tableView.frame = scrollView.bounds;
    [self stoneobs_ui_configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    self.view.backgroundColor = [UIColor whiteColor];
    NSString *stoneobs_temp_jScript =
    @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta); var imgs = document.getElementsByTagName('img');for (var i in imgs){imgs[i].style.maxWidth='100%';imgs[i].style.height='auto';}";
    
    WKUserScript *stoneobs_temp_wkUScript = [[WKUserScript alloc] initWithSource:stoneobs_temp_jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    
    WKUserContentController *stoneobs_temp_wkUController = [[WKUserContentController alloc] init];
    
    [stoneobs_temp_wkUController addUserScript:stoneobs_temp_wkUScript];
    
    WKWebViewConfiguration *stoneobs_temp_wkWebConfig = [[WKWebViewConfiguration alloc] init];
    
    stoneobs_temp_wkWebConfig.userContentController = stoneobs_temp_wkUController;
    
    
    self.webView = [[WKWebView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME configuration:stoneobs_temp_wkWebConfig];
    [self.view addSubview:self.webView];
    
    [self.webView loadHTMLString:self.model.detail baseURL:nil];
    
    
        
}
#pragma mark --WKNavigationDelegate

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{


}
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
{

    NSLog(@"%@",error);


}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error;
{


}
@end
